-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(TcpSocketClientBase): update generic class #6327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideRefactored the TCP socket client to use a generic base with a pluggable ISocketClient, introduced configuration via SocketClientOptions and an updated factory API, extracted raw socket logic into DefaultSocketClient, centralized logging/error handling/cleanup in the base class, and revised tests to cover the new design. ER diagram for SocketClientOptions configurationerDiagram
SOCKET_CLIENT_OPTIONS {
int ReceiveBufferSize
bool IsAutoReceive
int ConnectTimeout
int SendTimeout
int ReceiveTimeout
IPEndPoint LocalEndPoint
}
DEFAULT_TCP_SOCKET_CLIENT ||--o| SOCKET_CLIENT_OPTIONS : configures
Class diagram for new TCP socket client architectureclassDiagram
class ITcpSocketClient {
+bool IsConnected
+IPEndPoint LocalEndPoint
+Func<Memory<byte>, Task> ReceivedCallBack
+IDataPackageHandler DataPackageHandler
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<Memory<byte>> ReceiveAsync(CancellationToken)
+ValueTask CloseAsync()
}
class TcpSocketClientBase~TSocketClient~ {
#TSocketClient? Client
+ILogger? Logger
+IPEndPoint LocalEndPoint
+bool IsConnected
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<Memory<byte>> ReceiveAsync(CancellationToken)
+ValueTask CloseAsync()
#abstract TSocketClient CreateSocketClient(IPEndPoint)
}
class ISocketClient {
+bool IsConnected
+IPEndPoint LocalEndPoint
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<int> ReceiveAsync(Memory<byte>, CancellationToken)
+ValueTask CloseAsync()
}
class DefaultSocketClient {
+bool IsConnected
+IPEndPoint LocalEndPoint
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<int> ReceiveAsync(Memory<byte>, CancellationToken)
+ValueTask CloseAsync()
}
class DefaultTcpSocketClient {
+DefaultTcpSocketClient(SocketClientOptions)
+DefaultSocketClient CreateSocketClient(IPEndPoint)
}
class SocketClientOptions {
+int ReceiveBufferSize
+bool IsAutoReceive
+int ConnectTimeout
+int SendTimeout
+int ReceiveTimeout
+IPEndPoint LocalEndPoint
}
ITcpSocketClient <|.. TcpSocketClientBase~TSocketClient~
ISocketClient <|.. DefaultSocketClient
TcpSocketClientBase~DefaultSocketClient~ <|-- DefaultTcpSocketClient
DefaultTcpSocketClient o-- SocketClientOptions
TcpSocketClientBase~TSocketClient~ o-- ISocketClient
Class diagram for updated ITcpSocketFactory APIclassDiagram
class ITcpSocketFactory {
+ITcpSocketClient GetOrCreate(string name, Action<SocketClientOptions> valueFactory)
+void Remove(string name)
}
class DefaultTcpSocketFactory {
+ITcpSocketClient GetOrCreate(string name, Action<SocketClientOptions> valueFactory)
}
ITcpSocketFactory <|.. DefaultTcpSocketFactory
DefaultTcpSocketFactory o-- DefaultTcpSocketClient
DefaultTcpSocketClient o-- SocketClientOptions
Class diagram for ISocketClient interface and DefaultSocketClient implementationclassDiagram
class ISocketClient {
+bool IsConnected
+IPEndPoint LocalEndPoint
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<int> ReceiveAsync(Memory<byte>, CancellationToken)
+ValueTask CloseAsync()
}
class DefaultSocketClient {
+bool IsConnected
+IPEndPoint LocalEndPoint
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<int> ReceiveAsync(Memory<byte>, CancellationToken)
+ValueTask CloseAsync()
}
ISocketClient <|.. DefaultSocketClient
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ArgoZhang - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6327 +/- ##
=======================================
Coverage 99.99% 99.99%
=======================================
Files 715 717 +2
Lines 31514 31568 +54
Branches 4449 4455 +6
=======================================
+ Hits 31513 31567 +54
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6326
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Genericize the TCP socket client framework to support custom socket client implementations, introduce configurable client options, and enhance connection, send, and receive operations with timeout, cancellation, and logging support.
New Features:
Bug Fixes:
Enhancements:
Tests: